package com.pengtu.gsj.controller.jsbz;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.jsbz.InfoManagement;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.jsbz.InfoManagementService;

/**
 * 
 * 2017年6月12日 上午9:25:13
 * @author heyong
 * @version 1.0.0
 *
 */

@Controller
@RequestMapping("infoManagement")
public class InfoManagementController extends DefaultBaseController {
	
	
	@Autowired
	private InfoManagementService infoManagementService;
	
	
	@ModelAttribute
	public InfoManagement load(String id){
		InfoManagement infoManagement;
		if(StringUtils.isNotEmpty(id)){
			infoManagement = infoManagementService.getInfoManagementById(id);
		}else{
			infoManagement = new InfoManagement();
		}
		return infoManagement;
	}
	
	/**
	 * 页面跳转
	 * @return
	 */
	@RequestMapping("listInfo")
	@Token(save = true)
	public String showLisfInfo() {
		return "jsbz/InfoManagement_list";
	}
	
	/**
	 * 数据加载
	 * @param page
	 * @param request
	 * @return
	 */
	@RequestMapping(value="list", produces = "application/json; charset=utf-8")
	@ResponseBody
	public Page<InfoManagement> getInfoManagementList(Page<InfoManagement> page, HttpServletRequest request){
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("systemDate");
			page.setOrder(Page.ASC);
		}
		page = infoManagementService.findInfoManagements(page, queryFilter);
		return page;
	}
	
	/**
	 * 保存
	 * @param infoManagement
	 * @return
	 */
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	@Token(remove = true)
	public boolean saveInfoManagement(@ModelAttribute InfoManagement infoManagement){
		infoManagementService.saveInfoManagement(infoManagement);
		return true;
	}
	
	
	/**
	 * 加载数据
	 * @param infoManagement
	 * @return
	 */
	@RequestMapping(value="show")
	@ResponseBody                                                     
	public InfoManagement showInfoManagement (@ModelAttribute InfoManagement infoManagement){
		return infoManagement;
	}
	
	@RequestMapping(value="delete")
	@ResponseBody
	public boolean delateInfoManagement(@ModelAttribute InfoManagement infoManagement){
		infoManagementService.delateInfoManagement(infoManagement);
		return true;
	}
	
}
